package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.ElderService;
import com.elder.business.service.IElderServiceService;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 老人购买服务Controller
 * 
 * @author elder
 * @date 2024-04-11
 */
@RestController
public class ElderServiceController extends BaseController
{
    @Autowired
    private IElderServiceService elderServiceService;

    /**
     * 查询老人购买服务列表
     */
    @Anonymous
    @GetMapping("/business/service/list")
    public TableDataInfo list(String elderName, String startTime,String endTime,Integer pageNum,Integer pageSize)
    {
        return elderServiceService.getElderServiceList(elderName,startTime,endTime,pageNum,pageSize);
    }

    /**
     * 导出老人购买服务列表
     */
    @Anonymous
    @Log(title = "老人购买服务", businessType = BusinessType.EXPORT)
    @PostMapping("/business/service/export")
    public void export(HttpServletResponse response, ElderService elderService)
    {
        List<ElderService> list = elderServiceService.selectElderServiceList(elderService);
        ExcelUtil<ElderService> util = new ExcelUtil<ElderService>(ElderService.class);
        util.exportExcel(response, list, "老人购买服务数据");
    }

    /**
     * 获取老人购买服务详细信息
     */
    @Anonymous
    @GetMapping(value = "/business/service/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elderServiceService.selectElderServiceById(id));
    }

    /**
     * 新增老人购买服务
     */
    @Anonymous
    @Log(title = "老人购买服务", businessType = BusinessType.INSERT)
    @PostMapping("/business/service")
    public AjaxResult add(@RequestBody ElderService elderService)
    {
        return toAjax(elderServiceService.insertElderService(elderService));
    }

    /**
     * 修改老人购买服务
     */
    @Anonymous
    @Log(title = "老人购买服务", businessType = BusinessType.UPDATE)
    @PutMapping("/business/service")
    public AjaxResult edit(@RequestBody ElderService elderService)
    {
        return toAjax(elderServiceService.updateElderService(elderService));
    }

    /**
     * 删除老人购买服务
     */
    @Anonymous
    @Log(title = "老人购买服务", businessType = BusinessType.DELETE)
	@DeleteMapping("/business/service/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elderServiceService.deleteElderServiceByIds(ids));
    }

    @Anonymous
    @Log(title = "老人购买服务", businessType = BusinessType.UPDATE)
    @RequestMapping("/business/service/serviceId")
    public AjaxResult update(Long serviceId,String status)
    {
        return toAjax(elderServiceService.updateElderServiceisFinish(serviceId,status));
    }
}
